package maze;

import java.util.LinkedList;
import java.util.Queue;

public class geneticMaze{
	private static int[][] maze={{0,0,0,0,0,0,0,0,0,0},
								 {0,0,0,1,0,0,0,1,0,0},
								 {0,1,0,0,0,1,1,1,0,0},
								 {2,1,1,1,1,1,0,0,0,0},
								 {0,0,1,1,0,0,0,0,0,0},
								 {1,1,0,1,0,0,0,1,0,0},
								 {0,1,1,1,1,1,1,1,1,0},
								 {0,0,0,0,0,1,0,0,0,0},
								 {0,1,1,0,0,1,1,1,1,0},
								 {0,0,0,0,0,5,0,0,0,0}};
	private static final int enter=2;
	private static final int exit=5;
	
	public static void main(String[] args){
		for(int i=0; i<maze.length; i++)
			for(int j=0; j<maze[i].length; j++)
				if(maze[i][j]==enter)
					findPath(i,j,"("+i+","+j+")");
	}
	
	public static void findPath(int point_i, int point_j, String path){
		Queue<int[]> queue=new LinkedList<int[]>();
		if(maze[point_i][point_j]==exit){
			System.out.println(path);
		}
		else{
			maze[point_i][point_j]=0;
			addEightPoint(point_i,point_j,queue);
		}
		
		while(!queue.isEmpty()){
			int[] point=queue.poll();
			findPath(point[0],point[1],path+"->("+point[0]+","+point[1]+")");
		}
	}
	
	public static boolean isInMaze(int i, int j){
		return i>0 && j>0 && i<maze.length && j<maze[0].length;
	}
	
	public static void addOnePoint(int i, int j, Queue<int[]> queue){
		if(isInMaze(i,j))
			if(maze[i][j]>0){
				int[] point={i,j};
				queue.offer(point);
				if(maze[i][j]!=exit)
					maze[i][j]=0;
			}
	}
	
	public static void addEightPoint(int i, int j, Queue<int[]> queue){
		addOnePoint(i-1,j,queue);
		addOnePoint(i,j+1,queue);
		addOnePoint(i+1,j,queue);
		addOnePoint(i,j-1,queue);
	}
}